package com.zige.zige.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zige.zige.R;
import com.zige.zige.constants.UrlConsts;
import com.zige.zige.task.PostRequestTask;
import com.zige.zige.task.TaskExecutor;
import com.zige.zige.utils.SystemUtils;

import java.util.HashMap;

/**
 * Created by Fei on 2016/1/4.....
 */
public class ActivityVideoWebActivirt extends BaseActivity {

    private WebView web_view;
    private TextView tv_title;
    private String mUrl,mTitle,id,showreddot;
    private LinearLayout lay_back;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vrweb);
        showLoadingDialog();
        mTitle= getIntent().getStringExtra("activityName");
        mUrl = getIntent().getStringExtra("activityUrl");
        Log.e("wu","web"+mUrl);
        showreddot = getIntent().getStringExtra("showreddot");
        if(!TextUtils.isEmpty(getIntent().getStringExtra("menuId"))){
            id = getIntent().getStringExtra("menuId");
            sendMenuOclick(id);
            Log.e("wu","eee"+id);

        }else {
            Log.e("wu","ooo"+id);

            id =null;
        }

        initView();
    }

    private void initView(){
        lay_back = serchViewById(R.id.lay_back);
        lay_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tv_title = serchViewById(R.id.title_name);
        tv_title.setText(mTitle);

        web_view = serchViewById(R.id.web_view);
        web_view.loadUrl("http://b.eqxiu.com/s/B5aE6ch0");
        web_view.setWebViewClient(new ActivityVideoWeb());
        web_view.setWebChromeClient(new WebChromeClient());
        web_view.getSettings().setDomStorageEnabled(true);
        web_view.getSettings().setJavaScriptEnabled(true);

    }

    private class ActivityVideoWeb extends WebViewClient{

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            closeLoadingDialog();

        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }
    }


    private void sendMenuOclick(String id){
        Log.e("wu","    55555");
        if(id !=null || !id.equals("null")){
            HashMap<String,String >  params = new HashMap<>();
            params.put("deviceId", SystemUtils.getDeviceKey(ActivityVideoWebActivirt.this));
            params.put("menuId",id);
            TaskExecutor.getInstance().execute(new PostRequestTask(params,ActivityVideoWebActivirt.this, UrlConsts.MENU_OLICK) {
                @Override
                protected void handleResponse(String response) {
                    Log.e("wu","di点击菜单"+response);
                }
            });
        }
    }

}
